


use ppi

-- // checksum failed custom error
exec sp_addmessage @msgnum = 505050, @severity = 16, @msgtext = N'%s(%s) checksum compare failed', @replace = 'REPLACE', @lang = 'us_english'
GO

-- // not found custom error
exec sp_addmessage @msgnum = 505060, @severity = 16, @msgtext = N'%s(%s) does not exist', @replace = 'REPLACE', @lang = 'us_english'
GO

-- // unit test custom error
exec sp_addmessage @msgnum = 505070, @severity = 16, @msgtext = N'%s Test Failed. Expected< %s > Actual< %s > %s', @replace = 'REPLACE', @lang = 'us_english'
GO



use ppi

if exists (select * from dbo.sysobjects where id = object_id(N'v_tb_Vendor_Distribution_Transformers') and OBJECTPROPERTY(id, N'IsProcedure') = 0)
drop view v_tb_Vendor_Distribution_Transformers
GO

create view v_tb_Vendor_Distribution_Transformers as
	/* 	Initial Generated Date:  lunes, 23 de agosto de 2010 
		Purpose: Selected record(s) from the table; this view is the source for all procedures' select statements
	*/
	
select
	 [Vendor_Distribution_Transformers_TransformerId] as [Vendor_Distribution_Transformers_TransformerId]
	,[Vendor_Distribution_PoleFk] as [Vendor_Distribution_PoleFk]
	,[Utility_Asset_Transformers_TransformerFk] as [Utility_Asset_Transformers_TransformerFk]
	,[Latitude] as [Latitude]
	,[Longitude] as [Longitude]
	,[Comments] as [Comments]
	,[UtilityNumber] as [UtilityNumber]
	,[SerialNumber] as [SerialNumber]
	,[TransformerTypeFk] as [TransformerTypeFk]
	,[Manufacturer] as [Manufacturer]
	,[Primary] as [Primary]
	,[Secondary] as [Secondary]
	,[TypeFk] as [TypeFk]
	,[ClassFk] as [ClassFk]
	,[PhaseFk] as [PhaseFk]
	,[Arrestor] as [Arrestor]
	,[DualRated] as [DualRated]
	,[Pre1978] as [Pre1978]
	,[PCBTypeFk] as [PCBTypeFk]
	,[PPM] as [PPM]
	,[CreatedDate] as [CreatedDate]
	,[ArrestorKv] as [ArrestorKv]
	,[Cutout] as [Cutout]
	,[CutoutKv] as [CutoutKv]
	,[TransformerNumber] as [TransformerNumber]
	,[CanFk] as [CanFk]
	-- customization may be required for FriendlyName
	,Left(CONVERT(varchar(255), [Vendor_Distribution_Transformers_TransformerId]), 255) as [FriendlyName]
from
	tb_Vendor_Distribution_Transformers
GO





use ppi

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorDistributionTransformer_Test') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorDistributionTransformer_Test
GO


create proc up_VendorDistributionTransformer_Test
	@Vendor_Distribution_Transformers_TransformerId int
as
	/* 	Initial Generated Date:  lunes, 23 de agosto de 2010 
		Purpose: Test if a record exists, using the primary key
	*/

SET NOCOUNT ON	
	
if exists(
	select [Vendor_Distribution_Transformers_TransformerId] 
	from [tb_Vendor_Distribution_Transformers] source
	where [source].[Vendor_Distribution_Transformers_TransformerId] = @Vendor_Distribution_Transformers_TransformerId)
begin
	return(1)
end
else
begin
	return(0)
end
GO






use ppi

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorDistributionTransformer_Select') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorDistributionTransformer_Select
GO

create proc up_VendorDistributionTransformer_Select
	 @Vendor_Distribution_Transformers_TransformerId int = null 
	,@Vendor_Distribution_PoleFk int = null 
	,@Utility_Asset_Transformers_TransformerFk int = null 
	,@Latitude float = null 
	,@Longitude float = null 
	,@Comments ntext = null 
	,@UtilityNumber nvarchar(100) = null 
	,@SerialNumber nvarchar(100) = null 
	,@TransformerTypeFk int = null 
	,@Manufacturer nvarchar(100) = null 
	,@Primary nvarchar(100) = null 
	,@Secondary nvarchar(100) = null 
	,@TypeFk int = null 
	,@ClassFk int = null 
	,@PhaseFk int = null 
	,@Arrestor bit = null 
	,@DualRated bit = null 
	,@Pre1978 bit = null 
	,@PCBTypeFk int = null 
	,@PPM nvarchar(100) = null 
	,@CreatedDate datetime = null 
	,@ArrestorKv int = null 
	,@Cutout bit = null 
	,@CutoutKv int = null 
	,@TransformerNumber nvarchar(100) = null 
	,@CanFk int = null 
as
	/* 	Initial Generated Date:  lunes, 23 de agosto de 2010 
		Purpose: Selected record(s) based on the passed arguments; no arguments returns all
	*/

SET NOCOUNT ON	

select * from v_tb_Vendor_Distribution_Transformers
where
		IsNull([v_tb_Vendor_Distribution_Transformers].[Vendor_Distribution_Transformers_TransformerId], -1) = Coalesce(@Vendor_Distribution_Transformers_TransformerId, [v_tb_Vendor_Distribution_Transformers].[Vendor_Distribution_Transformers_TransformerId], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Vendor_Distribution_PoleFk], -1) = Coalesce(@Vendor_Distribution_PoleFk, [v_tb_Vendor_Distribution_Transformers].[Vendor_Distribution_PoleFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Utility_Asset_Transformers_TransformerFk], -1) = Coalesce(@Utility_Asset_Transformers_TransformerFk, [v_tb_Vendor_Distribution_Transformers].[Utility_Asset_Transformers_TransformerFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Latitude], -1) = Coalesce(@Latitude, [v_tb_Vendor_Distribution_Transformers].[Latitude], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Longitude], -1) = Coalesce(@Longitude, [v_tb_Vendor_Distribution_Transformers].[Longitude], -1)
	AND	IsNull(Convert(varchar(2000), [v_tb_Vendor_Distribution_Transformers].[Comments]), '') = Coalesce(Convert(varchar(2000), @Comments), Convert(varchar(2000), [v_tb_Vendor_Distribution_Transformers].[Comments]), '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[UtilityNumber], '') = Coalesce(@UtilityNumber, [v_tb_Vendor_Distribution_Transformers].[UtilityNumber], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[SerialNumber], '') = Coalesce(@SerialNumber, [v_tb_Vendor_Distribution_Transformers].[SerialNumber], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[TransformerTypeFk], -1) = Coalesce(@TransformerTypeFk, [v_tb_Vendor_Distribution_Transformers].[TransformerTypeFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Manufacturer], '') = Coalesce(@Manufacturer, [v_tb_Vendor_Distribution_Transformers].[Manufacturer], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Primary], '') = Coalesce(@Primary, [v_tb_Vendor_Distribution_Transformers].[Primary], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Secondary], '') = Coalesce(@Secondary, [v_tb_Vendor_Distribution_Transformers].[Secondary], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[TypeFk], -1) = Coalesce(@TypeFk, [v_tb_Vendor_Distribution_Transformers].[TypeFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[ClassFk], -1) = Coalesce(@ClassFk, [v_tb_Vendor_Distribution_Transformers].[ClassFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[PhaseFk], -1) = Coalesce(@PhaseFk, [v_tb_Vendor_Distribution_Transformers].[PhaseFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Arrestor], 0) = Coalesce(@Arrestor, [v_tb_Vendor_Distribution_Transformers].[Arrestor], 0)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[DualRated], 0) = Coalesce(@DualRated, [v_tb_Vendor_Distribution_Transformers].[DualRated], 0)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Pre1978], 0) = Coalesce(@Pre1978, [v_tb_Vendor_Distribution_Transformers].[Pre1978], 0)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[PCBTypeFk], -1) = Coalesce(@PCBTypeFk, [v_tb_Vendor_Distribution_Transformers].[PCBTypeFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[PPM], '') = Coalesce(@PPM, [v_tb_Vendor_Distribution_Transformers].[PPM], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[CreatedDate], '1/1/1900 12:00AM') = Coalesce(@CreatedDate, [v_tb_Vendor_Distribution_Transformers].[CreatedDate], '1/1/1900 12:00AM')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[ArrestorKv], -1) = Coalesce(@ArrestorKv, [v_tb_Vendor_Distribution_Transformers].[ArrestorKv], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Cutout], 0) = Coalesce(@Cutout, [v_tb_Vendor_Distribution_Transformers].[Cutout], 0)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[CutoutKv], -1) = Coalesce(@CutoutKv, [v_tb_Vendor_Distribution_Transformers].[CutoutKv], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[TransformerNumber], '') = Coalesce(@TransformerNumber, [v_tb_Vendor_Distribution_Transformers].[TransformerNumber], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[CanFk], -1) = Coalesce(@CanFk, [v_tb_Vendor_Distribution_Transformers].[CanFk], -1)
GO





use ppi

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorDistributionTransformer_Select_Top1') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorDistributionTransformer_Select_Top1
GO

create proc up_VendorDistributionTransformer_Select_Top1
	 @Vendor_Distribution_Transformers_TransformerId int = null 
	,@Vendor_Distribution_PoleFk int = null 
	,@Utility_Asset_Transformers_TransformerFk int = null 
	,@Latitude float = null 
	,@Longitude float = null 
	,@Comments ntext = null 
	,@UtilityNumber nvarchar(100) = null 
	,@SerialNumber nvarchar(100) = null 
	,@TransformerTypeFk int = null 
	,@Manufacturer nvarchar(100) = null 
	,@Primary nvarchar(100) = null 
	,@Secondary nvarchar(100) = null 
	,@TypeFk int = null 
	,@ClassFk int = null 
	,@PhaseFk int = null 
	,@Arrestor bit = null 
	,@DualRated bit = null 
	,@Pre1978 bit = null 
	,@PCBTypeFk int = null 
	,@PPM nvarchar(100) = null 
	,@CreatedDate datetime = null 
	,@ArrestorKv int = null 
	,@Cutout bit = null 
	,@CutoutKv int = null 
	,@TransformerNumber nvarchar(100) = null 
	,@CanFk int = null 
as
	/* 	Initial Generated Date:  lunes, 23 de agosto de 2010 
		Purpose: Selected top 1 record based on the passed arguments; no arguments returns all
	*/

SET NOCOUNT ON	

select TOP 1 * from v_tb_Vendor_Distribution_Transformers
where
		IsNull([v_tb_Vendor_Distribution_Transformers].[Vendor_Distribution_Transformers_TransformerId], -1) = Coalesce(@Vendor_Distribution_Transformers_TransformerId, [v_tb_Vendor_Distribution_Transformers].[Vendor_Distribution_Transformers_TransformerId], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Vendor_Distribution_PoleFk], -1) = Coalesce(@Vendor_Distribution_PoleFk, [v_tb_Vendor_Distribution_Transformers].[Vendor_Distribution_PoleFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Utility_Asset_Transformers_TransformerFk], -1) = Coalesce(@Utility_Asset_Transformers_TransformerFk, [v_tb_Vendor_Distribution_Transformers].[Utility_Asset_Transformers_TransformerFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Latitude], -1) = Coalesce(@Latitude, [v_tb_Vendor_Distribution_Transformers].[Latitude], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Longitude], -1) = Coalesce(@Longitude, [v_tb_Vendor_Distribution_Transformers].[Longitude], -1)
	AND	IsNull(Convert(varchar(2000), [v_tb_Vendor_Distribution_Transformers].[Comments]), '') = Coalesce(Convert(varchar(2000), @Comments), Convert(varchar(2000), [v_tb_Vendor_Distribution_Transformers].[Comments]), '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[UtilityNumber], '') = Coalesce(@UtilityNumber, [v_tb_Vendor_Distribution_Transformers].[UtilityNumber], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[SerialNumber], '') = Coalesce(@SerialNumber, [v_tb_Vendor_Distribution_Transformers].[SerialNumber], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[TransformerTypeFk], -1) = Coalesce(@TransformerTypeFk, [v_tb_Vendor_Distribution_Transformers].[TransformerTypeFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Manufacturer], '') = Coalesce(@Manufacturer, [v_tb_Vendor_Distribution_Transformers].[Manufacturer], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Primary], '') = Coalesce(@Primary, [v_tb_Vendor_Distribution_Transformers].[Primary], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Secondary], '') = Coalesce(@Secondary, [v_tb_Vendor_Distribution_Transformers].[Secondary], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[TypeFk], -1) = Coalesce(@TypeFk, [v_tb_Vendor_Distribution_Transformers].[TypeFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[ClassFk], -1) = Coalesce(@ClassFk, [v_tb_Vendor_Distribution_Transformers].[ClassFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[PhaseFk], -1) = Coalesce(@PhaseFk, [v_tb_Vendor_Distribution_Transformers].[PhaseFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Arrestor], 0) = Coalesce(@Arrestor, [v_tb_Vendor_Distribution_Transformers].[Arrestor], 0)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[DualRated], 0) = Coalesce(@DualRated, [v_tb_Vendor_Distribution_Transformers].[DualRated], 0)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Pre1978], 0) = Coalesce(@Pre1978, [v_tb_Vendor_Distribution_Transformers].[Pre1978], 0)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[PCBTypeFk], -1) = Coalesce(@PCBTypeFk, [v_tb_Vendor_Distribution_Transformers].[PCBTypeFk], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[PPM], '') = Coalesce(@PPM, [v_tb_Vendor_Distribution_Transformers].[PPM], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[CreatedDate], '1/1/1900 12:00AM') = Coalesce(@CreatedDate, [v_tb_Vendor_Distribution_Transformers].[CreatedDate], '1/1/1900 12:00AM')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[ArrestorKv], -1) = Coalesce(@ArrestorKv, [v_tb_Vendor_Distribution_Transformers].[ArrestorKv], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[Cutout], 0) = Coalesce(@Cutout, [v_tb_Vendor_Distribution_Transformers].[Cutout], 0)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[CutoutKv], -1) = Coalesce(@CutoutKv, [v_tb_Vendor_Distribution_Transformers].[CutoutKv], -1)
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[TransformerNumber], '') = Coalesce(@TransformerNumber, [v_tb_Vendor_Distribution_Transformers].[TransformerNumber], '')
	AND	IsNull([v_tb_Vendor_Distribution_Transformers].[CanFk], -1) = Coalesce(@CanFk, [v_tb_Vendor_Distribution_Transformers].[CanFk], -1)
GO




use ppi

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorDistributionTransformer_Insert') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorDistributionTransformer_Insert
GO

create proc up_VendorDistributionTransformer_Insert
	 @Vendor_Distribution_Transformers_TransformerId int =null OUTPUT  
	,@Vendor_Distribution_PoleFk int  
	,@Utility_Asset_Transformers_TransformerFk int = null  
	,@Latitude float = null  
	,@Longitude float = null  
	,@Comments ntext = null  
	,@UtilityNumber nvarchar(100) = null  
	,@SerialNumber nvarchar(100) = null  
	,@TransformerTypeFk int = null  
	,@Manufacturer nvarchar(100) = null  
	,@Primary nvarchar(100) = null  
	,@Secondary nvarchar(100) = null  
	,@TypeFk int = null  
	,@ClassFk int = null  
	,@PhaseFk int = null  
	,@Arrestor bit = null  
	,@DualRated bit = null  
	,@Pre1978 bit = null  
	,@PCBTypeFk int = null  
	,@PPM nvarchar(100) = null  
	,@CreatedDate datetime = null  
	,@ArrestorKv int = null  
	,@Cutout bit = null  
	,@CutoutKv int = null  
	,@TransformerNumber nvarchar(100) = null  
	,@CanFk int = null  
as
	/* 	Initial Generated Date:  lunes, 23 de agosto de 2010 
		Purpose: Inserts a new record; missing arguments are set as their default (typically null)
	*/

SET NOCOUNT ON	
--int

insert tb_Vendor_Distribution_Transformers 
	(
	
	 [Vendor_Distribution_PoleFk] 
	,[Utility_Asset_Transformers_TransformerFk] 
	,[Latitude] 
	,[Longitude] 
	,[Comments] 
	,[UtilityNumber] 
	,[SerialNumber] 
	,[TransformerTypeFk] 
	,[Manufacturer] 
	,[Primary] 
	,[Secondary] 
	,[TypeFk] 
	,[ClassFk] 
	,[PhaseFk] 
	,[Arrestor] 
	,[DualRated] 
	,[Pre1978] 
	,[PCBTypeFk] 
	,[PPM] 
	,[CreatedDate] 
	,[ArrestorKv] 
	,[Cutout] 
	,[CutoutKv] 
	,[TransformerNumber] 
	,[CanFk] 
	)
	values
	(
	
	 @Vendor_Distribution_PoleFk 
	,@Utility_Asset_Transformers_TransformerFk 
	,@Latitude 
	,@Longitude 
	,@Comments 
	,@UtilityNumber 
	,@SerialNumber 
	,@TransformerTypeFk 
	,@Manufacturer 
	,@Primary 
	,@Secondary 
	,@TypeFk 
	,@ClassFk 
	,@PhaseFk 
	,@Arrestor 
	,@DualRated 
	,@Pre1978 
	,@PCBTypeFk 
	,@PPM 
	,@CreatedDate 
	,@ArrestorKv 
	,@Cutout 
	,@CutoutKv 
	,@TransformerNumber 
	,@CanFk 
	)
set @Vendor_Distribution_Transformers_TransformerId = scope_identity()
select * from v_tb_Vendor_Distribution_Transformers where Vendor_Distribution_Transformers_TransformerId = @Vendor_Distribution_Transformers_TransformerId

GO




use ppi

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorDistributionTransformer_Update') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorDistributionTransformer_Update
GO


create proc up_VendorDistributionTransformer_Update
	 @Vendor_Distribution_Transformers_TransformerId int  
	,@Vendor_Distribution_PoleFk int = null  
	,@Utility_Asset_Transformers_TransformerFk int = null  
	,@Latitude float = null  
	,@Longitude float = null  
	,@Comments ntext = null  
	,@UtilityNumber nvarchar(100) = null  
	,@SerialNumber nvarchar(100) = null  
	,@TransformerTypeFk int = null  
	,@Manufacturer nvarchar(100) = null  
	,@Primary nvarchar(100) = null  
	,@Secondary nvarchar(100) = null  
	,@TypeFk int = null  
	,@ClassFk int = null  
	,@PhaseFk int = null  
	,@Arrestor bit = null  
	,@DualRated bit = null  
	,@Pre1978 bit = null  
	,@PCBTypeFk int = null  
	,@PPM nvarchar(100) = null  
	,@CreatedDate datetime = null  
	,@ArrestorKv int = null  
	,@Cutout bit = null  
	,@CutoutKv int = null  
	,@TransformerNumber nvarchar(100) = null  
	,@CanFk int = null  
	,@OriginalVendor_Distribution_Transformers_TransformerId int  = null --Original PrimaryKey
	
as
	/* 	Initial Generated Date:  lunes, 23 de agosto de 2010 
		Purpose: Updates an existing record, verifying exist; missing arguments persist original record value
		NOTE: this version of the update allows up to write nulls to the table.
	*/

SET NOCOUNT ON	

if @OriginalVendor_Distribution_Transformers_TransformerId is null
	set @OriginalVendor_Distribution_Transformers_TransformerId = @Vendor_Distribution_Transformers_TransformerId

-- test
declare @Result bit
execute @Result = up_VendorDistributionTransformer_Test @OriginalVendor_Distribution_Transformers_TransformerId
if (not @Result = 1)
begin
	Declare @x varchar(100)
	Set @x = Convert(Varchar(100), @Vendor_Distribution_Transformers_TransformerId)
	raiserror(505060, 16, 1, 'VendorDistributionTransformer', @x)
	return
end

-- proceed
update tb_Vendor_Distribution_Transformers 
set

	 [Vendor_Distribution_PoleFk] = IsNull(@Vendor_Distribution_PoleFk, [source].[Vendor_Distribution_PoleFk])
	,[Utility_Asset_Transformers_TransformerFk] =  @Utility_Asset_Transformers_TransformerFk
	,[Latitude] =  @Latitude
	,[Longitude] =  @Longitude
	,[Comments] =  @Comments
	,[UtilityNumber] =  @UtilityNumber
	,[SerialNumber] =  @SerialNumber
	,[TransformerTypeFk] =  @TransformerTypeFk
	,[Manufacturer] =  @Manufacturer
	,[Primary] =  @Primary
	,[Secondary] =  @Secondary
	,[TypeFk] =  @TypeFk
	,[ClassFk] =  @ClassFk
	,[PhaseFk] =  @PhaseFk
	,[Arrestor] =  @Arrestor
	,[DualRated] =  @DualRated
	,[Pre1978] =  @Pre1978
	,[PCBTypeFk] =  @PCBTypeFk
	,[PPM] =  @PPM
	,[CreatedDate] =  @CreatedDate
	,[ArrestorKv] =  @ArrestorKv
	,[Cutout] =  @Cutout
	,[CutoutKv] =  @CutoutKv
	,[TransformerNumber] =  @TransformerNumber
	,[CanFk] =  @CanFk
	
from tb_Vendor_Distribution_Transformers source
where
	[source].[Vendor_Distribution_Transformers_TransformerId] = @OriginalVendor_Distribution_Transformers_TransformerId


select * from v_tb_Vendor_Distribution_Transformers where Vendor_Distribution_Transformers_TransformerId = @Vendor_Distribution_Transformers_TransformerId
GO





use ppi

if exists (select * from dbo.sysobjects where id = object_id(N'up_VendorDistributionTransformer_Delete') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_VendorDistributionTransformer_Delete
GO


create proc up_VendorDistributionTransformer_Delete
	@Vendor_Distribution_Transformers_TransformerId int
as
	/* 	Initial Generated Date:  lunes, 23 de agosto de 2010 
		Purpose: Deletes an existing record, verifying exist
	*/

SET NOCOUNT ON	

-- test
declare @Result bit
execute @Result = up_VendorDistributionTransformer_Test @Vendor_Distribution_Transformers_TransformerId
if (not @Result = 1)
begin
	Declare @x varchar(100)
	Set @x = Convert(Varchar(100), @Vendor_Distribution_Transformers_TransformerId)
	raiserror(505060, 16, 1, 'VendorDistributionTransformer', @x)
	return
end

-- proceed
delete from tb_Vendor_Distribution_Transformers 
where [Vendor_Distribution_Transformers_TransformerId] = @Vendor_Distribution_Transformers_TransformerId

GO


